package com.zr.service.impl;

import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.zr.dao.FunctionDao;
import com.zr.dao.impl.FunctionDaoImpl;
import com.zr.model.Function;
import com.zr.service.FunctionService;



/**
 * @Description
 * @author 郑少杰
 * @date 2017年9月14日 下午2:57:05
 * @version V1.3.1
 */

public class FunctionServiceImpl implements FunctionService {

    FunctionDao func = new FunctionDaoImpl();

    /**
     * Description
     * 
     * @return
     * @see com.zr.service.FunctionService#getAllFuncs()
     */

    @Override
    public String getAllFuncs() {
        List<Function> list = func.selectAllFuncs();
        String fids = "";
        for (int i = 0; i < list.size(); i++) {
            if (i == list.size() - 1) {
                fids += String.valueOf(list.get(i).getFid());
            } else {
                fids += String.valueOf(list.get(i).getFid()) + ",";
            }
        }
        return fids;
    }

    /**
     * Description
     * 
     * @param page
     * @param pagesize
     * @return
     * @see com.zr.service.FunctionService#getFuns(int, int)
     */
    @Override
    public JSONObject getFuns(int page, int pagesize) {
        JSONObject jsonObject = new JSONObject();
        int num = func.selectAllFuncs().size();
        List<Function> list = func.selAllFuncs(page, pagesize);
        jsonObject.put("total", num);
        jsonObject.put("rows", list);
        return jsonObject;
    }

    /**
     * Description
     * 
     * @return
     * @see com.zr.service.FunctionService#getParentNodeFun()
     */

    @Override
    public JSONArray getParentNodeFun() {

        return func.getAllParentNodes(-1);
    }

    /**
     * Description
     * 
     * @param name
     * @param state
     * @param fpid
     * @return
     * @see com.zr.service.FunctionService#addFuncs(java.lang.String, java.lang.String, int)
     */

    @Override
    public boolean addFuncs(String name, String state, int fpid) {
        // TODO Auto-generated method stub
        return func.insertFuncs(name, state, fpid);
    }

}
